//package com.dongdong.controller;
//
//import cn.hutool.core.util.RandomUtil;
//import com.alibaba.fastjson.JSONObject;
//import com.aliyun.auth.credentials.Credential;
//import com.aliyun.auth.credentials.provider.StaticCredentialProvider;
//import com.aliyun.sdk.service.dysmsapi20170525.AsyncClient;
//import com.aliyun.sdk.service.dysmsapi20170525.models.SendSmsRequest;
//import com.aliyun.sdk.service.dysmsapi20170525.models.SendSmsResponse;
//import com.dongdong.em.Result;
//import com.google.gson.Gson;
//import darabonba.core.client.ClientOverrideConfiguration;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.cloud.context.config.annotation.RefreshScope;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RequestParam;
//import org.springframework.web.bind.annotation.RestController;
//
//import java.util.concurrent.CompletableFuture;
//import java.util.concurrent.ExecutionException;
//
//@RestController
//@RequestMapping("msg")
//@RefreshScope     //热更新
//public class MsgController {
//
//    @Value("${apicode.accessKeyId}")
//    private String accessKeyId;
//
//    @Value("${apicode.accessKeySecret}")
//    private String accessKeySecret;
//
//     @Value("${apicode.region}")
//    private String region;
//
//    @Value("${apicode.setEndpointOverride}")
//    private String setEndpointOverride;
//
//     @Value("${apicode.signName}")
//     private String signName;
//
//    @Value("${apicode.templateCode}")
//    private String templateCode;
//
//    @Value("${apicode.phoneNumbers}")
//    private String phoneNumbers;
//
//
//    @GetMapping("getMsg")
//    public Result getMsg(@RequestParam String phone){
//
//        // Configure Credentials authentication information, including ak, secret, token
//        StaticCredentialProvider provider = StaticCredentialProvider.create(Credential.builder()
//                .accessKeyId(accessKeyId)//LTAI5tRVYYLS4pnrXYxMosn8
//                .accessKeySecret(accessKeySecret)//uUi4zbsHPHe1s2LM1Zu4X9v0YRBCgn
//                //.securityToken("<your-token>") // use STS token
//                .build());
//
//        // Configure the Client
//        AsyncClient client = AsyncClient.builder()
//                .region(region) // Region ID
//                //.httpClient(httpClient) // Use the configured HttpClient, otherwise use the default HttpClient (Apache HttpClient)
//                .credentialsProvider(provider)
//                //.serviceConfiguration(Configuration.create()) // Service-level configuration
//                // Client-level configuration rewrite, can set Endpoint, Http request parameters, etc.
//                .overrideConfiguration(
//                        ClientOverrideConfiguration.create()
//                                .setEndpointOverride(setEndpointOverride)
//                        //.setConnectTimeout(Duration.ofSeconds(30))
//                )
//                .build();
//
//        String s = RandomUtil.randomNumbers(6);
//        JSONObject json = new JSONObject();
//        json.put("code",s);
//        // Parameter settings for API request
//        SendSmsRequest sendSmsRequest = SendSmsRequest.builder()
//                .signName(signName)
//                .templateCode(templateCode)
//                .phoneNumbers(phone)
//                .templateParam(json.toJSONString())
//                // Request-level configuration rewrite, can set Http request parameters, etc.
//                // .requestConfiguration(RequestConfiguration.create().setHttpHeaders(new HttpHeaders()))
//                .build();
//
//        // Asynchronously get the return value of the API request
//        CompletableFuture<SendSmsResponse> response = client.sendSms(sendSmsRequest);
//        // Synchronously get the return value of the API request
//        SendSmsResponse resp = null;
//        try {
//            resp = response.get();
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        } catch (ExecutionException e) {
//            e.printStackTrace();
//        }
//        System.out.println(new Gson().toJson(resp));
//        // Asynchronous processing of return values
//        /*response.thenAccept(resp -> {
//            System.out.println(new Gson().toJson(resp));
//        }).exceptionally(throwable -> { // Handling exceptions
//            System.out.println(throwable.getMessage());
//            return null;
//        });*/
//
//        // Finally, close the client
//        client.close();
//        return Result.OK();
//    }
//}
